package com.puzzlebazar.client.services;

import java.util.LinkedList;
import java.util.List;
import java.util.Vector;

import com.google.gwt.user.client.rpc.RemoteService;
import com.puzzlebazar.client.main.model.PuzzleListInfoImpl.ListType;
import com.puzzlebazar.client.puzzle.model.History;
import com.puzzlebazar.client.puzzle.model.PuzzleModel;
import com.puzzlebazar.client.puzzleinfo.HistoryInfo;
import com.puzzlebazar.client.puzzleinfo.NewPuzzleInfo;
import com.puzzlebazar.client.puzzleinfo.PuzzleAndHistoryInfo;
import com.puzzlebazar.client.puzzleinfo.PuzzleInfo;
import com.puzzlebazar.client.puzzleinfo.PuzzleInfo.Status;

public interface PuzzleService extends RemoteService {

	/**
	 * Retrieves the list of all the histories
	 * 
	 * @param authorEmail The email of the user for which to retrieve histories, null to retrieve for all users
	 * @param puzzleInfoKey The key of the puzzle info for which to retrieve histories
	 * @return The list of the requested histories
	 */
	LinkedList<HistoryInfo> getHistoryList(String authorEmail, String puzzleInfoKey);

	/**
	 * Retrieves the list of all server-side puzzles for a given genre 
	 * 
	 * @param listType The type of puzzles to retrieve
	 * @param genreList The list of all the genres to retrieve (null for all genres)
	 * @return The list of puzzles corresponding to the request
	 */
	public List<PuzzleInfo> getPuzzleList(ListType listType, Vector<String> genreList );

	/**
	 * Saves the given puzzle on the server, adds the puzzle if it doesn't exists
	 * 
	 * @param newPuzzleInfo The user-controlled information regarding this newly created puzzle
	 * @return The key of the PuzzleInfo object associated with the current puzzle, null if failed
	 */
	public String createNewPuzzleOrTutorial( NewPuzzleInfo newPuzzleInfo );
	
	/**
	 * Loads a puzzle from the server
	 * 
	 * @param puzzleInfoKey The key of the puzzle info to load
	 * @return The associated detailed information, or null if an error occured
	 */
	public PuzzleInfo loadPuzzle( String puzzleInfoKey );

	/**
	 * Loads a tutorial from the server
	 * 
	 * @param puzzleInfoKey The key of the puzzle info for the tutorial to load
	 * @return An object containing both the puzzle information and the history information
	 */
	public PuzzleAndHistoryInfo loadTutorial( String puzzleInfoKey );

	/**
	 * Change the title of a specific puzzle
	 * 
	 * @param puzzleKey The key of the puzzle to rename
	 * @param title The new title of this puzzle
	 * @return true if rename succeeded, false otherwise
	 */
	public boolean renamePuzzleOrTutorial(String puzzleKey, String title);

	/**
	 * Changes the status of a puzzle
	 * 
	 * @param puzzleKey The key of the puzzle to rename
	 * @param status The new desired status
	 * @return true if status was correctly changed, false otherwise
	 */
	public boolean changePuzzleOrTutorialStatus(String puzzleKey, Status status);
	
	/**
	 * Deletes a puzzle from the server
	 * 
	 * @param puzzleKey The key of the puzzle to delete
	 * @return True if the puzzle was successfully deleted, false otherwise
	 */
	public boolean deletePuzzleOrTutorial(String puzzleKey);


	/**
	 * Changes the model associated with this puzzle. Size will be changed automatically,
	 * and possibly the validity of the puzzle
	 * 
	 * @param model The model to attach to this puzzle
	 * @return True if the model was successfully saved, false otherwise
	 */
	public boolean savePuzzleModel(PuzzleModel model);

	/**
	 * Creates or save the passed history in the datastore. The history will be created if its history
	 * info key is null. In this case, the author will be set as the current user.
	 * 
	 * @param model The history to save
	 * @param puzzleInfoKey The key to the puzzle attached with this history
	 * @param completed True if the history is for a correctly completed puzzle, false otherwise
	 * @return The key of the history info attached with this history if successfull, null if failed
	 */
	public String saveHistory(History model, String puzzleInfoKey, boolean completed );

	/**
	 * Creates or save the passed history in the datastore. The history will be created if its history
	 * info key is null. In this case, the author will be set as the current user.
	 * 
	 * @param historyModel The history to save
	 * @param puzzleModel The puzzle attached to this history
	 * @return The key of the puzzle info attached with this tutorial if successfull, null if failed
	 */
	public String saveTutorial(History historyModel, PuzzleModel puzzleModel );
	
	/**
	 * Loads a puzzle attached with an history given information about the history
	 * 
	 * @param historyInfoKey The key to the history to load
	 * @return An object containing both the puzzle information and the history information
	 */
	public PuzzleAndHistoryInfo loadHistory(String historyInfoKey);



	
}
